Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
import() use static string work well but string variable not work.And throwing error "Error: Cannot find module 'xxx module path'"

Using static import mode works well.For example:

import App from './App.js';

And in common general style of using "import()" works well:

async function fun(){
    const App = async ()=> await import("./App.js");
    console.log(await App() )//it load module successfully
}
fun();

When i use a string variable parameter for import(),it dosn't work.And it will throw error:

async function fun(){
    const path = "./App.js";
    const App = async ()=> await import(path).catch(err=>console.log(err));
    await App() //Error: Cannot find module 'xxx module path'
}
fun();

So,i must load all modules before using.Could i dynamic import modules like that demo?

I go through the mdn docs about dynamic import but not get helpful information.

And require() performs the same.

Does someone have the same questions?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to use ./ and not ../, as ../ is the parent directory and not the current directory. I don't know why this only applies to dynamic imports, but thats just some weird thing about it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda